package mh.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import mh.modules.sys.entity.NoticesEntity;
import mh.modules.sys.service.NoticesService;
import mh.common.utils.PageUtils;
import mh.common.utils.R;



/**
 * 
 *
 * @author zhongxiang
 * @email 
 * @date 2024-10-23 17:17:02
 */
@RestController
@RequestMapping("sys/notices")
@Slf4j
public class NoticesController {
    @Autowired
    private NoticesService noticesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:notices:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = noticesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:notices:info")
    public R info(@PathVariable("id") Long id){
		NoticesEntity notices = noticesService.getById(id);

        return R.ok().put("notices", notices);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:notices:save")
    public R save(@RequestBody NoticesEntity notices){
		noticesService.save(notices);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:notices:update")
    public R update(@RequestBody NoticesEntity notices){
        log.info("NoticesEntity{}",notices);
		noticesService.updateById(notices);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:notices:delete")
    public R delete(@RequestBody Long[] ids){
		noticesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 公告展示
     * @param
     * @return
     */
    @RequestMapping("/isactive")
    public R isactive(){
       R r = noticesService.isActive();
        return R.ok(r);
    }


}
